Skip to content

feat(markdown-alert): localize alert titles for Traditional Chinese - #137

Merged
JaylyDev merged 1 commit into
mainfrom
jayly/markdown-alert-zh-hant
Dec 5, 2026
Merged

JaylyDev merged 1 commit into
mainfrom
jayly/markdown-alert-zh-hant

Conversation

@JaylyDev

@JaylyDev JaylyDev commented Dec 5, 2026

Copy link
Copy Markdown
Owner

Why

Markdown alerts show English titles such as Note on Traditional Chinese pages like /zh/hk-tunnels-tolls/. The site already sets the page language on <html lang> during static export in src/pages/_document.tsx and during client navigation in src/pages/_app.tsx. Reading <html lang> in CSS keeps every page in sync without passing a locale argument to parseMarkdown.

What changed

The change spans three files.

  • src/remark-github-alerts/index.ts adds markdown-alert-title-default to default alert title paragraphs and wraps the English text in <span class="markdown-alert-title-text">. Custom inline titles and options.titles overrides still render as plain text without those classes. CSS localization then leaves author-written titles untouched.
  • src/styles/markdown-alert/github-i18n.css defines Traditional Chinese titles (備註, 提示, 重要, 警告, and 注意) and sets --markdown-alert-title-text-display to none on matching <html> elements. The selector matches [lang="zh" i], :lang(zh-Hant), :lang(zh-HK), :lang(zh-TW), and :lang(zh-MO). That selector covers every Traditional Chinese page on the site without matching zh-CN or zh-Hans. Using CSS avoids a flash of English text on static exports and updates immediately when document.documentElement.lang changes. Keeping all i18n rules in src/styles/markdown-alert/github-i18n.css leaves src/styles/markdown-alert/github-base.css untouched.
  • src/pages/_app.tsx imports src/styles/markdown-alert/github-i18n.css next to the other markdown-alert stylesheets. Every route loads the localized alert rules globally.

Screenshots

Traditional Chinese (<html lang="zh-HK">) English (<html lang="en">)
Traditional Chinese markdown alert showing 備註 on /zh/hk-tunnels-tolls/ English markdown alert showing Note on /hk-tunnels-tolls/

## Why

Markdown alerts show English titles such as `Note` on Traditional Chinese pages like `/zh/hk-tunnels-tolls/`. The site already sets the page language on `<html lang>` during static export in `src/pages/_document.tsx` and during client navigation in `src/pages/_app.tsx`. Reading `<html lang>` in CSS keeps every page in sync without passing a locale argument to `parseMarkdown`.

## What changed

The change spans three files.

- `src/remark-github-alerts/index.ts` adds `markdown-alert-title-default` to default alert title paragraphs and wraps the English text in `<span class="markdown-alert-title-text">`. Custom inline titles and `options.titles` overrides still render as plain text without those classes. CSS localization then leaves author-written titles untouched.
- `src/styles/markdown-alert/github-i18n.css` defines Traditional Chinese titles (`備註`, `提示`, `重要`, `警告`, and `注意`) and sets `--markdown-alert-title-text-display` to `none` on matching `<html>` elements. The selector matches `[lang="zh" i]`, `:lang(zh-Hant)`, `:lang(zh-HK)`, `:lang(zh-TW)`, and `:lang(zh-MO)`. That selector covers every Traditional Chinese page on the site without matching `zh-CN` or `zh-Hans`. Using CSS avoids a flash of English text on static exports and updates immediately when `document.documentElement.lang` changes. Keeping all i18n rules in `src/styles/markdown-alert/github-i18n.css` leaves `src/styles/markdown-alert/github-base.css` untouched.
- `src/pages/_app.tsx` imports `src/styles/markdown-alert/github-i18n.css` next to the other `markdown-alert` stylesheets. Every route loads the localized alert rules globally.

## Screenshots

| Traditional Chinese (`<html lang="zh-HK">`) | English (`<html lang="en">`) |
| --- | --- |
| <img width="420" alt="Traditional Chinese markdown alert showing 備註 on /zh/hk-tunnels-tolls/" src="https://gist.githubusercontent.com/JaylyDev/e742895506cc3c3f32e8e3197edc4be2/raw/bee588f28dd17e17883157bb1f35ae6e04c2e008/markdown-alert-zh-hk.png" /> | <img width="420" alt="English markdown alert showing Note on /hk-tunnels-tolls/" src="https://gist.githubusercontent.com/JaylyDev/e742895506cc3c3f32e8e3197edc4be2/raw/bee588f28dd17e17883157bb1f35ae6e04c2e008/markdown-alert-en.png" /> |
@JaylyDev
JaylyDev merged commit 935fdf7 into main Dec 5, 2026
2 checks passed
@JaylyDev
JaylyDev deleted the jayly/markdown-alert-zh-hant branch December 5, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant